<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>轮播图</title>
    <style>
        .box{
            width:600px;
            height: 350px;
            background-image: url(./imgs/1.jpg);
            background-size: cover;
            position: relative;
            left:700px;
            top:250px;
            border-radius: 30px;
        }
        .imgbox{
            list-style: none;
        }
        ul li{
            float: left;
            margin-left:30px;
            position: relative;
            top: 360px;
            left: 150px;
        }
        input{
            margin-left:30px;
        }
    </style>
</head>
<body>
    <div class="box">
        <ul class="imgbox">
            <li><form >
                <input type="radio" name='img' value='0' checked>
                <input type="radio" name='img' value="1">
                <input type="radio" name='img' value="2">
            </form></li>
        </ul>
    </div>

    <script>
        const box = document.getElementsByClassName('box')[0];
        const btns = document.getElementsByTagName('input')
        const imgs = ['./imgs/1.jpg','./imgs/2.jpg','./imgs/3.jpg'];

        var index = 0;
        for(let i in btns){
            btns[i].onclick = function(e){
                box.style.backgroundImage = 'url('+imgs[i]+')';
                index = e.target.value;
            }
        }
        
        setInterval(function(){          
                box.style.backgroundImage = 'url('+imgs[index]+')';
                btns[index].checked = true;
                if(index==2){
                    index=0;
                }else{
                    index++;
                }
            },1000)
    </script>
</body>
</html>